﻿using System;
using System.Windows;
using System.Windows.Data;

namespace Purdue.Converters
{
    /// <summary>
    /// Converts bool to Visibility, with false being converted to Hidden instead of Collapsed.
    /// </summary>
    public class BooleanToHiddenOrVisibleConverter : IValueConverter
    {
        #region IValueConverter Members

        /// <summary>
        /// Converts a Boolean value to a Visibility enumeration value,
        /// with false being converted to Hidden.
        /// </summary>
        /// <param name="value">The Boolean value to convert. This value can be a standard Boolean value or a nullable Boolean value. </param>
        /// <param name="targetType">The parameter is not used.</param>
        /// <param name="parameter">The parameter is not used.</param>
        /// <param name="culture">The parameter is not used.</param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool visible = (bool)value;
            return visible ? Visibility.Visible : Visibility.Hidden;
        }

        /// <summary>
        /// Converts a Visibility enumeration value to a Boolean value.
        /// </summary>
        /// <param name="value">A Visibility enumeration value.</param>
        /// <param name="targetType">The parameter is not used.</param>
        /// <param name="parameter">The parameter is not used.</param>
        /// <param name="culture">The parameter is not used.</param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Visibility visibility = (Visibility)value;
            return (visibility == Visibility.Visible);
        }

        #endregion
    }
}
